package com.peng.test.sort;

import java.util.Arrays;

/**
 * BubbleSort
 *
 * @author: lupeng6
 * @create: 2020/12/10 14:46
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = {10, 7, 2, 4, 7, 62, 3, 4, 2, 1, 8, 9, 19};
        new Solution().sort(arr);
        Arrays.stream(arr).forEach(System.out::println);
    }

    static class Solution {
        public void sort(int[] arr) {
            int temp;
            for (int i = 0; i < arr.length; i++) {
                for (int j = 1; j < arr.length - i; j++) {
                    if (arr[j - 1] > arr[j]) {
                        temp = arr[j - 1];
                        arr[j - 1] = arr[j];
                        arr[j] = temp;
                    }
                }
            }
        }
    }

}
